/**
 * 
 */
package fr.univ_tln.inf9.exaplanning.api.cours;

import java.util.Date;

import javax.swing.event.EventListenerList;

import fr.univ_tln.inf9.exaplanning.api.cours.event.dayListener;
import fr.univ_tln.inf9.exaplanning.api.cours.event.dayChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.end_timeChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.end_timeListener;
import fr.univ_tln.inf9.exaplanning.api.cours.event.start_timeChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.start_timeListener;
import fr.univ_tln.inf9.exaplanning.api.utilisateur.event.NameChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.utilisateur.event.NameListener;

/**
 * @author pivi
 *
 *TODO: faire le lien avec MetaCreneau
 */
public class TimeSlot {
	
	private Date start_time;
	private Date end_time;
	private String day;
	/**
	 * @param start_time
	 * @param end_time
	 * @param day
	 */
	
	private EventListenerList listeners;
	
	public TimeSlot(Date start_time, Date end_time, String day) {
		super();
		this.start_time = start_time;
		this.end_time = end_time;
		this.day = day;
	}
	/**
	 * @return the start_time
	 */
	public Date getStart_time() {
		return start_time;
	}
	/**
	 * @param start_time the start_time to set
	 */
	public void setStart_time(Date start_time) {
		this.start_time = start_time;
		fireStart_timeChanged();
	}
	
	private void fireStart_timeChanged() {
		start_timeListener[] listenerList = (start_timeListener[])listeners.getListeners(start_timeListener.class);
		
		for(start_timeListener listener : listenerList){
			listener.start_timeChanged(new start_timeChangedEvent(this, getStart_time()));
		}	
	}
	
	public void addStart_timeListener(start_timeListener listener){
		listeners.add(start_timeListener.class, listener);
	}
	
	public void removeStart_timeListener(start_timeListener l){
		 listeners.remove(start_timeListener.class, l);
	}
	/**
	 * @return the end_time
	 */
	public Date getEnd_time() {
		return end_time;
	}
	/**
	 * @param heure_f the heure_f to set
	 */
	public void setEnd_time(Date end_time) {
		this.end_time = end_time;
		fireEnd_timeChanged();
	}
	
	private void fireEnd_timeChanged() {
		end_timeListener[] listenerList = (end_timeListener[])listeners.getListeners(end_timeListener.class);
		
		for(end_timeListener listener : listenerList){
			listener.end_timeChanged(new end_timeChangedEvent(this, getEnd_time()));
		}	
	}
	
	public void addEnd_timeListener(end_timeListener listener){
		listeners.add(end_timeListener.class, listener);
	}
	
	public void removeEnd_timeListener(end_timeListener l){
		 listeners.remove(end_timeListener.class, l);
	}
	/**
	 * @return the day
	 */
	public String getDay() {
		return day;
	}
	/**
	 * @param day the day to set
	 */
	public void setDay(String day) {
		this.day = day;
		fireDayChanged();
	}
	
	private void fireDayChanged() {
		dayListener[] listenerList = (dayListener[])listeners.getListeners(dayListener.class);
		
		for(dayListener listener : listenerList){
			listener.dayChanged(new dayChangedEvent(this, getDay()));
		}	
	}
	
	public void addDayListener(dayListener listener){
		listeners.add(dayListener.class, listener);
	}
	
	public void removeDayListener(dayListener l){
		 listeners.remove(dayListener.class, l);
	}

}
